﻿using ConfExpert.Forms.Base;
using ConfExpert.Forms.Du4;
using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms.Depo
{
    public partial class RollHistory : XForm
    {
        public RollHistory()
        {
            InitializeComponent();
        }

        private void RollHistory_Load(object sender, EventArgs e)
        {
            
            textEdit1.EditValueChanged+=textEdit1_EditValueChanged;
            btnModify.ItemClick += btnModify_ItemClick;
            btnModify.Visibility = ytk(129) ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never;
            btnModify.Enabled = false;
        }

        void btnModify_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (TopDuzeltme duzeltme = new TopDuzeltme(intParse(textEdit1.EditValue)))
            {
                duzeltme.ShowDialog();
            }
        }

        void textEdit1_EditValueChanged(object sender, EventArgs e)
        {
            DataSet data = Session.DataManager.ExecuteDataSet("GetRollHistory", intParse(textEdit1.EditValue));

            gridView1.Init(data.Tables[0]);
            gvHist.Init(data.Tables[1]);
            gvLoc.Init(data.Tables[2]);

            gridView1.YanYanaGetir("Product:ShelfId");
            gridView1.MakeColumnInvisible("TelaId", "ProductId");

            int BrandId = -1;

            if (data.Tables[0].Columns["BrandId"] != null)
                BrandId = data.Tables[0].Rows[0]["BrandId"].ToInt(-1);

            btnModify.Enabled = gridView1.DataRowCount > 0 && 
                (ytk(130) && BrandId == 47 || isAdmin);   //F.Seda,Gokce DU4, Admin: tüm topları değiştirebilir

            gvHist.MakeColumnInvisible("WebRezerveId", "UserId");
            gvHist.SetCaptions("GelisPartisiLinesId:GPLId");
            gvHist.MakeColumnVisible(gvHist.Columns["Tarih"]);
            gvHist.Columns["Tarih"].DisplayFormat.FormatString = "g";

            gvHist.Columns["AyrimId"].VisibleIndex = gvHist.Columns["BrandId"].VisibleIndex;

            gridView1.BestFitColumns();
            gvHist.BestFitColumns();
            gvLoc.BestFitColumns();
        }
    }
}

